﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using OgilvyOne.Model;

public partial class admin_vico_dealer_list : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.headers.Text = new ColumnBll().LayeridColumnConNaiv(Request.Params["layerid"]);
            
        }
        GridView1DataBind();
    }

    private void GridView1DataBind()
    {
        VicoDealerModel q = new VicoDealerModel();
        int pagesize = 15;
        if (Request.Params["pageNum"] != null && Request.Params["pageNum"] != "")
        {
            try
            {
                GridView1.PageIndex = int.Parse(Request.Params["pageNum"]) - 1;
            }
            catch { }
        }
        if (Request.Params["rows"] != null && Request.Params["rows"] != "")
        {
            pagesize = int.Parse(Request.Params["rows"]);
            
        }
        this.rows.Text = pagesize.ToString();
        q.Dealernam = queryvalue.Text;

        DataSet ds = new VicoDealerBll().Query(q);

        GridView1.DataSource = ds;
        GridView1.PageSize = pagesize;
        GridView1.DataBind();

        this.pagehtml.Text = getPageHtml(GridView1.PageCount, GridView1.PageIndex + 1, ds.Tables[0].Rows.Count);
    }

    protected void Add_click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], ADD);
        Response.Redirect("dealer_detail.aspx?layerid=" + Request.Params["layerid"], true);
    }

    protected void Mod_click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], MOD);
        Response.Redirect("dealer_detail.aspx?id=" + ((LinkButton)sender).CommandArgument + "&layerid=" + Request.Params["layerid"], true);
    }

    protected void Del_click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], DEL);
        if (new VicoDealerBll().Del(int.Parse(((LinkButton)sender).CommandArgument)))
        {
            DataBind();
        }
    }
}
